$(function () {
    $("#sysUserGrid").Grid({
        url: '../sys/stat/user',
        colModel: [
            {label: '用户ID', name: 'userId', index: "user_id", key: true, hidden: true},
            {label: '员工号', name: 'username', index: "username", width: 75},
            {label: '姓名', name: 'post', index: "post", width: 75},
            {label: '所属部门', name: 'deptName', index: "deptName", width: 75},
            {label: '使用频次', name: 'times', width: 100,sortable: false}
        ]
    });
});

var vm = new Vue({
    el: '#sysUser',
    data: {
        q:{
            userName: '',
            beginTime:'',
            endTime:''
        },
        showList: true,
        title: null
    },
    methods: {
        query: function () {
            vm.reload();
        },
        reload: function (event) {
            vm.showList = true;
            // 整理下检索条件
            if(vm.q.beginTime){
                vm.q.beginTime = gmt2DateStr(vm.q.beginTime);
            }
            if(vm.q.endTime){
                vm.q.endTime = gmt2DateStr(vm.q.endTime);
            }

            var page = $("#sysUserGrid").jqGrid('getGridParam', 'page');
            $("#sysUserGrid").jqGrid('setGridParam', {
                postData: vm.q,
                page: page
            }).trigger("reloadGrid");
        },
        reloadSearch: function () {
            // 重置搜索条件
            vm.q.userName =  '';
            vm.q.beginTime =  '';
            vm.q.endTime =  '';
            vm.reload();
        }
    },
    watch: {
        beginTime: function (st) {
            if(st){
                vm.q.beginTime = gmt2DateStr(st);
            }
        },
        endTime: function (et) {
            if(et){
                vm.q.endTime = gmt2DateStr(et);
            }
        }
    }
});
